from Common.MySql import Sql
from Common.ReadYaml import ConfigYaml


class DeleteData(object):
    def __init__(self):
        self.sql_sale_reason = ConfigYaml(key='delete_sql_value').sql.format("order_after_sale_reason", "reason",
            "自动化")  #删除售后原因语句
        self.sql_tags = ConfigYaml(key='delete_sql_value').sql.format("virtual_order_tag", "name",
            "自动化")  # 删除订单标签
        self.sql_warehouse = ConfigYaml(key='delete_sql_value').sql.format("warehouse", "name",
                                                                      "自动化")  # 删除仓库
        self.sql_black = ConfigYaml(key='delete_sql_value').sql.format("virtual_order_blacklist", "name",
                                                                           "自动化")  # 删除黑名单

        self.sql_rule = ConfigYaml(key='delete_sql_value').sql.format("rule", "name",
                                                                       "自动化")  # 删除规则

        self.sql_shipping = ConfigYaml(key='delete_sql_value').sql.format("shipping_channel", "name",
                                                                      "自动化")  # 删除物流

        self.sql_supplier = ConfigYaml(key='delete_sql_value').sql.format("supplier", "name",
                                                                          "自动化")  # 删除供应商

        self.visit_record = "DELETE FROM `{}` WHERE {} LIKE '{}%';".format("visit_record", "supplier_name",
                                                                          "自动化专属供应商")  # 删除拜访记录

        self.follow_up_reason = ConfigYaml(key='delete_sql_value').sql.format("follow_up_reason", "reason",
                                                                          "自动化")  # 删除跟单原因

        self.check_inventory_reason = ConfigYaml(key='delete_sql_value').sql.format("check_inventory_reason", "reason",
                                                                              "自动化")  # 删除盘库原因

        self.category = ConfigYaml(key='delete_sql_value').sql.format("category", "name",
                                                                                    "自动化")  # 删除分类

        self.attribute_term = ConfigYaml(key='delete_sql_value').sql.format("attribute_term", "attr_term_name",
                                                                      "自动化")  # 删除分类

        self.brand = ConfigYaml(key='delete_sql_value').sql.format("brand", "name",
                                                                            "自动化")  # 删除分类

        self.srm_supplier = ConfigYaml(key='delete_sql_value').sql.format("t_supplier", "supplier_name",
                                                                   "自动化")  # 删除分类

    def delete_sale_reason(self):
        '''
        删除售后原因
        :return:
        '''
        Sql(self.sql_sale_reason, sqlname="erp_order").execute_sql()

    def delete_order_tags(self):
        '''
        删除订单标签
        :return:
        '''
        Sql(self.sql_tags, sqlname="erp_order").execute_sql()

    def delete_black(self):
        '''
        删除黑名单
        :return:
        '''
        Sql(self.sql_black, sqlname="erp_order").execute_sql()

    def delete_warehouse(self):
        '''
        删除仓库
        :return:
        '''
        Sql(self.sql_warehouse, sqlname="erp_warehouse").execute_sql()

    def delete_rule(self):
        '''
        删除规则
        :return:
        '''
        Sql(self.sql_rule, sqlname="erp_order").execute_sql()

    def delete_sql_shipping(self):
        '''
        删除物流
        :return:
        '''
        Sql(self.sql_shipping, sqlname="erp_shipping").execute_sql()

    def delete_sql_supplier(self):
        '''
        删除供应商
        :return:
        '''
        Sql(self.sql_supplier, sqlname="erp_supplier").execute_sql()

    def delete_visit_record(self):
        '''
        删除拜访记录
        :return:
        '''
        Sql(self.visit_record, sqlname="erp_purchase").execute_sql()

    def delete_follow_up_reason(self):
        '''
        删除跟单原因
        :return:
        '''
        Sql(self.follow_up_reason, sqlname="erp_purchase").execute_sql()

    def delete_check_inventory_reason(self):
        '''
        删除盘库原因
        :return:
        '''
        Sql(self.check_inventory_reason, sqlname="erp_warehouse").execute_sql()

    def delete_category(self):
        '''
        删除产品分类
        :return:
        '''
        Sql(self.category, sqlname="erp_product").execute_sql()

    def delete_attribute_term(self):
        '''
        删除属性
        :return:
        '''
        Sql(self.attribute_term, sqlname="erp_product").execute_sql()

    def delete_brand(self):
        '''
        删除品牌
        :return:
        '''
        Sql(self.brand, sqlname="erp_product").execute_sql()

    def delete_srm_supplier(self):
        '''
        删除srm供应工商
        :return:
        '''
        Sql(self.srm_supplier, sqlname="srm_user").execute_sql()

    def all_delete(self):
        self.delete_sale_reason()
        self.delete_order_tags()
        self.delete_black()
        self.delete_warehouse()
        self.delete_rule()
        self.delete_sql_shipping()
        self.delete_sql_supplier()
        self.delete_follow_up_reason()
        self.delete_check_inventory_reason()
        self.delete_category()
        self.delete_attribute_term()
        self.delete_brand()
        self.delete_srm_supplier()


if __name__ == "__main__":
    dl = DeleteData()
    dl.delete_srm_supplier()